<!DOCTYPE HTML>
<html lang="zh-CN">


<head><meta name="generator" content="Hexo 3.8.0">
    <meta charset="utf-8">
    <meta name="keywords" content="基于STM32+LDC1000的循迹小车, ZhengN_Blog">
    <meta name="description" content="1、前言这是2016年TI杯电子设计竞赛的作品，并获得了省一等奖。
2、竞赛题目每年的TI杯电子设计竞赛都会出A题~G题共七个题，我们团队平时主要做控制的多，所以这次竞赛我们选择控制类题目——自动循迹小车。该题题目及要求如下：


3、方案">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <meta name="renderer" content="webkit|ie-stand|ie-comp">
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <title>基于STM32+LDC1000的循迹小车 | ZhengN_Blog</title>
    <link rel="icon" type="image/jpeg" href="/favicon.jpg">

    <link rel="stylesheet" type="text/css" href="/libs/awesome/css/font-awesome.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/materialize/materialize.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/aos/aos.css">
    <link rel="stylesheet" type="text/css" href="/libs/animate/animate.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/lightGallery/css/lightgallery.min.css">
    <link rel="stylesheet" type="text/css" href="/css/matery.css">
    <link rel="stylesheet" type="text/css" href="/css/my.css">
    <style type="text/css">
        
    </style>

    <script src="/libs/jquery/jquery-2.2.0.min.js"></script>
<link rel="stylesheet" href="/css/prism-tomorrow.css" type="text/css"></head>


<body>

<header class="navbar-fixed">
    <nav id="headNav" class="bg-color nav-transparent">
        <div id="navContainer" class="nav-wrapper container">
            <div class="brand-logo">
                <a href="/" class="waves-effect waves-light">
                    
                    <img src="/medias/logo.png" class="logo-img" alt="LOGO">
                    
                    <span class="logo-span">ZhengN_Blog</span>
                </a>
            </div>
            

<a href="#" data-target="mobile-nav" class="sidenav-trigger button-collapse"><i class="fa fa-navicon"></i></a>
<ul class="right">
    
    <li class="hide-on-med-and-down">
        <a href="/" class="waves-effect waves-light">
            
            <i class="fa fa-home"></i>
            
            <span>首页</span>
        </a>
    </li>
    
    <li class="hide-on-med-and-down">
        <a href="/tags" class="waves-effect waves-light">
            
            <i class="fa fa-tags"></i>
            
            <span>标签</span>
        </a>
    </li>
    
    <li class="hide-on-med-and-down">
        <a href="/categories" class="waves-effect waves-light">
            
            <i class="fa fa-bookmark"></i>
            
            <span>分类</span>
        </a>
    </li>
    
    <li class="hide-on-med-and-down">
        <a href="/archives" class="waves-effect waves-light">
            
            <i class="fa fa-archive"></i>
            
            <span>归档</span>
        </a>
    </li>
    
    <li class="hide-on-med-and-down">
        <a href="/about" class="waves-effect waves-light">
            
            <i class="fa fa-user-circle-o"></i>
            
            <span>关于</span>
        </a>
    </li>
    
    <li class="hide-on-med-and-down">
        <a href="/friends" class="waves-effect waves-light">
            
            <i class="fa fa-address-book"></i>
            
            <span>友情链接</span>
        </a>
    </li>
    
    <li>
        <a href="#searchModal" class="modal-trigger waves-effect waves-light">
            <i id="searchIcon" class="fa fa-search" title="搜索"></i>
        </a>
    </li>
</ul>

<div id="mobile-nav" class="side-nav sidenav">

    <div class="mobile-head bg-color">
        
        <img src="/medias/logo.png" class="logo-img circle responsive-img">
        
        <div class="logo-name">ZhengN_Blog</div>
        <div class="logo-desc">
            
            printf(&#34;每天进步一点点~&#34;);
            
        </div>
    </div>

    

    <ul class="menu-list mobile-menu-list">
        
        <li>
            <a href="/" class="waves-effect waves-light">
                
                <i class="fa fa-fw fa-home"></i>
                
                首页
            </a>
        </li>
        
        <li>
            <a href="/tags" class="waves-effect waves-light">
                
                <i class="fa fa-fw fa-tags"></i>
                
                标签
            </a>
        </li>
        
        <li>
            <a href="/categories" class="waves-effect waves-light">
                
                <i class="fa fa-fw fa-bookmark"></i>
                
                分类
            </a>
        </li>
        
        <li>
            <a href="/archives" class="waves-effect waves-light">
                
                <i class="fa fa-fw fa-archive"></i>
                
                归档
            </a>
        </li>
        
        <li>
            <a href="/about" class="waves-effect waves-light">
                
                <i class="fa fa-fw fa-user-circle-o"></i>
                
                关于
            </a>
        </li>
        
        <li>
            <a href="/friends" class="waves-effect waves-light">
                
                <i class="fa fa-fw fa-address-book"></i>
                
                友情链接
            </a>
        </li>
        
        
        <li><div class="divider"></div></li>
        <li>
            <a href="https://github.com/zhengnianli/stm32_weather" class="waves-effect waves-light" target="_blank">
                <i class="fa fa-github-square fa-fw"></i>Fork Me
            </a>
        </li>
        
    </ul>
</div>

        </div>

        
            <style>
    .nav-transparent .github-corner {
        display: none !important;
    }

    .github-corner {
        position: absolute;
        z-index: 10;
        top: 0;
        right: 0;
        border: 0;
        transform: scale(1.1);
    }

    .github-corner svg {
        color: #0f9d58;
        fill: #fff;
        height: 64px;
        width: 64px;
    }

    .github-corner:hover .octo-arm {
        animation: a 0.56s ease-in-out;
    }

    .github-corner .octo-arm {
        animation: none;
    }

    @keyframes a {
        0%,
        to {
            transform: rotate(0);
        }
        20%,
        60% {
            transform: rotate(-25deg);
        }
        40%,
        80% {
            transform: rotate(10deg);
        }
    }
</style>

<a href="https://github.com/zhengnianli/stm32_weather" class="github-corner tooltipped hide-on-med-and-down" target="_blank" data-tooltip="Fork Me" data-position="left" data-delay="50">
    <svg viewbox="0 0 250 250" aria-hidden="true">
        <path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"/>
        <path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"/>
        <path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"/>
    </svg>
</a>
        
    </nav>

</header>





<div class="bg-cover pd-header post-cover" style="background-image: url('/medias/featureimages/12.jpg')">
    <div class="container">
        <div class="row">
            <div class="col s12 m12 l12">
                <div class="brand">
                    <div class="description center-align post-title">
                        基于STM32+LDC1000的循迹小车
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>



<main class="post-container content">

    
    <link rel="stylesheet" href="/libs/tocbot/tocbot.css">
<style>
    #articleContent h1::before,
    #articleContent h2::before,
    #articleContent h3::before,
    #articleContent h4::before,
    #articleContent h5::before,
    #articleContent h6::before {
        display: block;
        content: " ";
        height: 100px;
        margin-top: -100px;
        visibility: hidden;
    }

    #articleContent :focus {
        outline: none;
    }

    .toc-fixed {
        position: fixed;
        top: 64px;
    }

    .toc-widget {
        padding-left: 20px;
    }

    .toc-widget .toc-title {
        margin: 35px 0 15px 0;
        padding-left: 17px;
        font-size: 1.5rem;
        font-weight: bold;
        line-height: 1.5rem;
    }

    .toc-widget ol {
        padding: 0;
        list-style: none;
    }

    #toc-content ol {
        padding-left: 10px;
    }

    #toc-content ol li {
        padding-left: 10px;
    }

    #toc-content .toc-link:hover {
        color: #42b983;
        font-weight: 700;
        text-decoration: underline;
    }

    #toc-content .toc-link::before {
        background-color: transparent;
        max-height: 25px;
    }

    #toc-content .is-active-link {
        color: #42b983;
    }

    #toc-content .is-active-link::before {
        background-color: #42b983;
    }

    #floating-toc-btn {
        position: fixed;
        right: 20px;
        bottom: 76px;
        padding-top: 15px;
        margin-bottom: 0;
        z-index: 998;
    }

    #floating-toc-btn .btn-floating {
        width: 48px;
        height: 48px;
    }

    #floating-toc-btn .btn-floating i {
        line-height: 48px;
        font-size: 1.4rem;
    }
</style>
<div class="row">
    <div id="main-content" class="col s12 m12 l9">
        <!-- 文章内容详情 -->
<div id="artDetail">
    <div class="card">
        <div class="card-content article-info">
            <div class="row tag-cate">
                <div class="col s7">
                    
                    <div class="article-tag">
                        
                            <a href="/tags/嵌入式/" target="_blank">
                                <span class="chip bg-color">嵌入式</span>
                            </a>
                        
                            <a href="/tags/STM32/" target="_blank">
                                <span class="chip bg-color">STM32</span>
                            </a>
                        
                            <a href="/tags/作品/" target="_blank">
                                <span class="chip bg-color">作品</span>
                            </a>
                        
                            <a href="/tags/循迹小车/" target="_blank">
                                <span class="chip bg-color">循迹小车</span>
                            </a>
                        
                    </div>
                    
                </div>
                <div class="col s5 right-align">
                    
                    <div class="post-cate">
                        <i class="fa fa-bookmark fa-fw icon-category"></i>
                        
                            <a href="/categories/嵌入式/" class="post-category" target="_blank">
                                嵌入式
                            </a>
                        
                    </div>
                    
                </div>
            </div>

            <div class="post-info">
                <div class="post-date info-break-policy">
                    <i class="fa fa-calendar-minus-o fa-fw"></i>发布日期:&nbsp;&nbsp;
                    2019-04-02
                </div>

                
                    
                    <div class="info-break-policy">
                        <i class="fa fa-file-word-o fa-fw"></i>文章字数:&nbsp;&nbsp;
                        2.3k
                    </div>
                    

                    
                    <div class="info-break-policy">
                        <i class="fa fa-clock-o fa-fw"></i>阅读时长:&nbsp;&nbsp;
                        8 分
                    </div>
                    
                
				
				
                    <div id="busuanzi_container_page_pv" class="info-break-policy">
                        <i class="fa fa-eye fa-fw"></i>阅读次数:&nbsp;&nbsp;
                        <span id="busuanzi_value_page_pv"></span>
                    </div>
				
            </div>
        </div>
        <hr class="clearfix">
        <div class="card-content article-card-content">
            <div id="articleContent">
                <h2 id="1、前言"><a href="#1、前言" class="headerlink" title="1、前言"></a>1、前言</h2><p>这是2016年TI杯电子设计竞赛的作品，并获得了省一等奖。</p>
<h2 id="2、竞赛题目"><a href="#2、竞赛题目" class="headerlink" title="2、竞赛题目"></a>2、竞赛题目</h2><p>每年的TI杯电子设计竞赛都会出A题~G题共七个题，我们团队平时主要做控制的多，所以这次竞赛我们选择控制类题目——<code>自动循迹小车</code>。该题题目及要求如下：</p>
<p><a href="https://imgchr.com/i/ZFg6tU" target="_blank" rel="noopener"><img src="https://s2.ax1x.com/2019/06/23/ZFg6tU.md.png" alt></a></p>
<p><img src="https://s2.ax1x.com/2020/02/20/3Z4a1U.jpg" alt></p>
<h2 id="3、方案的选择及比较"><a href="#3、方案的选择及比较" class="headerlink" title="3、方案的选择及比较"></a>3、方案的选择及比较</h2><p><a href="https://imgchr.com/i/ZFg50x" target="_blank" rel="noopener"><img src="https://s2.ax1x.com/2019/06/23/ZFg50x.md.png" alt></a></p>
<p>一些功能的实现、方案选择的分析如下：</p>
<h3 id="3-1-主控芯片的选择"><a href="#3-1-主控芯片的选择" class="headerlink" title="3.1 主控芯片的选择"></a>3.1 主控芯片的选择</h3><p>我们选用STM32系列单片机中的<code>STM32F103RBT6</code>作为主控芯片。大学期间的参加的两次TI杯都没有用TI的MSP430作为主控，哈哈。因为比赛规则没有说禁止使用其他厂商的控制芯片，那我们当然选用我们相对熟悉的STM32来作为控制芯片。</p>
<p>本以为毕业后可以做STM32或者其他ARM内核芯片作为开发平台的工作，没想到还是与TI挂上了勾，现在工作用的是TI的某双核DSP芯片，正好也可以学习TI的产品。在这一方面学的知识越来越多，就感觉平台只是基础，关键还是应用，关键还是看使用芯片平台开发什么产品。这一段时间的学习，给我的感觉就是TI官方写的代码没ST官方写的代码漂亮~</p>
<h3 id="3-2-电机驱动方案"><a href="#3-2-电机驱动方案" class="headerlink" title="3.2 电机驱动方案"></a>3.2 电机驱动方案</h3><p>采用专用芯片<code>L298N</code>作为电机驱动芯片。L298N是一个具有高电压大电流的全桥驱动芯片，它相应频率高，一片L298N可以分别控制两个直流电机，而且还带有控制使能端。用该芯片作为电机驱动，操作方便，稳定性好，性能优良。L298N结合单片机可实现对小车速度的精确控制。</p>
<h3 id="3-3-传感器的选择"><a href="#3-3-传感器的选择" class="headerlink" title="3.3 传感器的选择"></a>3.3 传感器的选择</h3><p><code>方案1</code>：采用一片TI公司配发的<code>LDC1314</code>。LDC1314提供匹配良好的通道， 可实现差分测量与比率测量。LDC1314具有多通道且支持远程感测并且还具备有高分辨率。高分辨率通道可支持更大的感测范围，在两倍线圈直径范围外依然可保持良好的性能。 良好匹配的通道支持差分与比率测量。LDC1314与单片机通信方式为I2C方式。</p>
<p><code>方案2</code>：采用一片TI公司配发的<code>LDC1000</code>。LDC1000的通信方式为SPI通信，通道个数为1。LDC1000除了通信方式与通道个数与LDC1314不同之外，其他部分几乎与LDC1314兼容。</p>
<p>由于当时比赛时LCD1314的数量有限，所以我们选用方案2的LDC1000传感器来寻迹。因为LDC1000只有一路通道，线圈无论左偏还是右偏，检测回来的值都变小，但是我们可以使用软件的方式来弥补它的这一缺点，同样可以达到准确寻迹的目的。</p>
<h3 id="3-4-LCD1000的测量方案分析"><a href="#3-4-LCD1000的测量方案分析" class="headerlink" title="3.4 LCD1000的测量方案分析"></a>3.4 LCD1000的测量方案分析</h3><p><code>方案1</code>：采用一片电子开关（<code>CD4052</code>）作为辅助让LDC1000可以对两个线圈进行切换控制，以趋近与双通道的效果。</p>
<p><code>方案2</code>：采用一片<code>LDC1000</code>单独检测铁丝，让线圈绕着铁丝走倒V形、Z形或S形的方式让线圈沿着铁丝左右切割前进。</p>
<p>由于考虑到程序算法的问题，因此我们采用方案2测量。</p>
<h3 id="3-5-小车转向的方案分析"><a href="#3-5-小车转向的方案分析" class="headerlink" title="3.5 小车转向的方案分析"></a>3.5 小车转向的方案分析</h3><p><code>方案1</code>：使用舵机转向。可以输入一个周期性的正向脉冲信号来控制舵机，这个周期性脉冲信号的高电平时间通常在<code>1ms—2ms</code>之间，而低电平时间应在<code>5ms到20ms</code>之间，并不很严格，典型的20ms周期性脉冲的正脉冲宽度与微型伺服马达的输出臂位置的关系：输入正脉冲宽度为0.5ms时对应的输出臂为-90°，输入正脉冲宽度为1.0ms时对应的输出臂为-45°，输入正脉冲宽度为1.5ms时对应的输出臂为0°，输入正脉冲宽度为2.0ms时对应的输出臂为45°，输入正脉冲宽度为2.5ms时对应的输出臂为90°。所以使用舵机在小角度转弯时灵敏度并不高。</p>
<p><code>方案2</code>：利用电机的速度差转向。它具有调速范围广、起动转矩大、控制功率小等一系列优点。</p>
<p>由于考虑到舵机小角度转弯灵敏度低的问题，因此我们采用方案2测量。</p>
<h3 id="3-6-电机的选择"><a href="#3-6-电机的选择" class="headerlink" title="3.6 电机的选择"></a>3.6 电机的选择</h3><p><code>方案1</code>：采用直流电机。直流电机转动力矩大，响应快速，体积小，重量轻，直流电动机具有优良的调速特性，调速平滑、方便，调整范围广；过载能力强，能承受频繁的冲击负载，可实现频繁的无级快速启动、制动和反转,能满足各种不同的特殊运行要求，价格便宜。我们选用减速比为<code>1：74</code>的直流电机，减速后电机的转速为<code>100r/min</code>。</p>
<p><code>方案2</code>：采用步进电机。步进电机是一种将电脉冲信号转换成角位移或线位移的精密执行原件。控制方便，体积小，灵活性和可靠性高，具有瞬时启动和急速停止的优越性，比较适合本系统控制精度高的特点。但步进电机的抖动比较大，输出力矩较低，随转速的升高而下降，且在较高转速时会急剧下降，其转速较低，不适用于小车等有一定速度要求的系统，价格还比较昂贵，所以这里不采用此方案。</p>
<p>由于直流电机价格便宜、控制简单。而且选用车轮直径为6cm的电机时，最大速度可以达到<code>V=2πr·v=2*3.14*0.03*100/60=0.314m/s</code>，能够较好的满足系统的要求。因此选用方案1。</p>
<h2 id="4、软件及解决的算法分析"><a href="#4、软件及解决的算法分析" class="headerlink" title="4、软件及解决的算法分析"></a>4、软件及解决的算法分析</h2><h3 id="4-1-循迹算法分析"><a href="#4-1-循迹算法分析" class="headerlink" title="4.1 循迹算法分析"></a>4.1 循迹算法分析</h3><p>我们软件实现的整体思路很简单，首先看一下分析图：</p>
<p><a href="https://imgchr.com/i/ZF208e" target="_blank" rel="noopener"><img src="https://s2.ax1x.com/2019/06/23/ZF208e.md.png" alt></a></p>
<p>我们我们记<code>LDC1000</code>读回来的数字量为 <code>Ldc_Val</code>， 根据我们自己铺的轨道，当线圈中心置于铁丝正上方时（在图中3号位置）的 Ldc_Val约为 11000， 当线圈中心置于偏离铁丝一小段距离（图中4号位置）的 Ldc_Val 约为 9000，当线圈正好与铁丝相切时（图中1、4号位置）的 Ldc_Val 约为 5000。</p>
<p>我们设置了三种情况来控制小车循迹，一是当 <code>9000&lt;Ldc_Val&lt;11000</code>（当然，因为上限值与下限值都是一个大概值，所以这两个值可以根据实际测试需要修改)时，小车稍微往右偏一个小角度，小车右偏的条件左边电机转速大于右边电机转速（偏离的程度根据实际测试调整）。二是当 <code>5000&lt;Ldc_Val&lt;9000</code>（当然，因为上限值与下限值都是一个大概值，所以这个值可以根据实际测试需要修改)时，小车稍微往左偏一个小角度，小车左偏的条件右边电机转速大于左边电机转速（偏离的程度根据实际测试调整）。三是当 <code>Ldc_Val=9000</code>（这个值根据前面两种情况的修改而修改）时，小车稍微往左偏一个小角度，小车左偏的条件右边电机转速大于左边电机转速（偏离的程度根据实际测试调整）。如此反复（过弯的情况也是一样的），小车就会沿着铁丝做<code>Z 形</code>对铁丝做切割运动循迹前行。</p>
<h3 id="4-2-硬币的检测"><a href="#4-2-硬币的检测" class="headerlink" title="4.2 硬币的检测"></a>4.2 硬币的检测</h3><p>在除了上述三种情况下，再添加第四种范围，当<code>Ldc_Val&gt;12000</code>（此值根据实际测试调节）时，就是检测到硬币在铁丝边缘，此时蜂鸣器发声提示。但是，有些时候会导致蜂鸣器频繁发声，这种情况是因为蜂鸣器发声的 Ldc_Val 值太低，导致铁线处于线圈正下方时 Ldc_Val 值也会处于蜂鸣器发声的 Ldc_Val 范围内，这时可以把蜂鸣器发声的临界值调高些。</p>
<p>还有一种情况就是线圈会在没有硬币的地方会偶尔产生一个异常的数值，该数值处于蜂鸣器发声的 Ldc_Val 值范围导致蜂鸣器发声，对于这种情况，我们首先想到的是在程序上采用连续读取多个检测回来的数字量去除最大最小值的再求平均值的方法来滤除掉这些偶尔的异常值。</p>
<h3 id="4-3-程序主流程图"><a href="#4-3-程序主流程图" class="headerlink" title="4.3 程序主流程图"></a>4.3 程序主流程图</h3><p><a href="https://imgchr.com/i/ZkPbcD" target="_blank" rel="noopener"><img src="https://s2.ax1x.com/2019/06/24/ZkPbcD.md.png" alt></a></p>
<h2 id="5、实物图"><a href="#5、实物图" class="headerlink" title="5、实物图"></a>5、实物图</h2><p>小车共有三个轮子，其中车头两个轮子，车位一个万向轮（方便转弯），LDC1000安装在车头正前方。</p>
<p><a href="https://imgchr.com/i/ZkiK3T" target="_blank" rel="noopener"><img src="https://s2.ax1x.com/2019/06/24/ZkiK3T.md.png" alt></a></p>
<h2 id="6、代码获取"><a href="#6、代码获取" class="headerlink" title="6、代码获取"></a>6、代码获取</h2><blockquote>
<p><a href="https://github.com/zhengnianli/LDC1000_Track_Car" target="_blank" rel="noopener">https://github.com/zhengnianli/LDC1000_Track_Car</a></p>
</blockquote>
<hr>
<p>我的个人博客：<a href="https://www.lizhengnian.cn/">https://www.lizhengnian.cn/</a></p>
<p>我的微信公众号：嵌入式大杂烩</p>
<p>我的CSDN博客：<a href="https://blog.csdn.net/zhengnianli" target="_blank" rel="noopener">https://blog.csdn.net/zhengnianli</a></p>
<p><a href="https://imgchr.com/i/VcSFJJ" target="_blank" rel="noopener"><img src="https://s2.ax1x.com/2019/06/11/VcSFJJ.md.png" alt></a></p>

            </div>
            <hr>

            
            <style>
    #reward {
        margin: 40px 0;
        text-align: center;
    }

    #reward .reward-link {
        font-size: 1.88rem;
    }

    #reward .btn-floating:hover {
        box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2), 0 5px 15px rgba(0, 0, 0, 0.2);
    }

    #rewardModal {
        width: 320px;
        height: 350px;
    }

    #rewardModal .reward-title {
        margin: 15px auto;
        padding-bottom: 5px;
    }

    #rewardModal .modal-content {
        padding: 10px;
    }

    #rewardModal .close {
        position: absolute;
        right: 15px;
        top: 15px;
        color: rgba(0, 0, 0, 0.5);
        font-size: 1.3rem;
        line-height: 20px;
        cursor: pointer;
    }

    #rewardModal .close:hover {
        color: #ef5350;
        transform: scale(1.3);
        -moz-transform:scale(1.3);
        -webkit-transform:scale(1.3);
        -o-transform:scale(1.3);
    }

    #rewardModal .reward-tabs {
        margin: 0 auto;
        width: 210px;
    }

    .reward-tabs .tabs {
        height: 38px;
        margin: 10px auto;
        padding-left: 0;
    }

    .reward-content ul {
        padding-left: 0 !important;
    }

    .reward-tabs .tabs .tab {
        height: 38px;
        line-height: 38px;
    }

    .reward-tabs .tab a {
        color: #fff;
        background-color: #ccc;
    }

    .reward-tabs .tab a:hover {
        background-color: #ccc;
        color: #fff;
    }

    .reward-tabs .wechat-tab .active {
        color: #fff !important;
        background-color: #22AB38 !important;
    }

    .reward-tabs .alipay-tab .active {
        color: #fff !important;
        background-color: #019FE8 !important;
    }

    .reward-tabs .reward-img {
        width: 210px;
        height: 210px;
    }
</style>

<div id="reward">
    <a href="#rewardModal" class="reward-link modal-trigger btn-floating btn-large waves-effect waves-light red">赏</a>

    <!-- Modal Structure -->
    <div id="rewardModal" class="modal">
        <div class="modal-content">
            <a class="close modal-close"><i class="fa fa-close"></i></a>
            <h4 class="reward-title">欢迎关注ZhengN的微信公众号</h4>
            <div class="reward-content">
                <div class="reward-tabs">
                    <!--<ul class="tabs row">
                        <li class="tab col s6 alipay-tab waves-effect waves-light"><a href="#alipay">支付宝</a></li>
                        <li class="tab col s6 wechat-tab waves-effect waves-light"><a href="#wechat">微信公众号</a></li>
                    </ul>-->
					<!--
                    <div id="alipay">
                        <img src="" class="reward-img" alt="支付宝打赏二维码">
                    </div>
					-->
                    <div id="wechat">
                        <img src="/medias/reward/wechat.jpg" class="reward-img" alt="微信公众号二维码">
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    $(function () {
        $('.tabs').tabs();
    });
</script>
            

            <link rel="stylesheet" type="text/css" href="/libs/share/css/share.min.css">

<div id="article-share">
    
    <div class="social-share" data-disabled="qzone" data-wechat-qrcode-helper="<p>微信里点“发现”->“扫一扫”二维码便可查看分享。</p>"></div>
    
</div>

<script src="/libs/share/js/social-share.min.js"></script>

            


        </div>
    </div>

    

    

    

    

    
        <style>
    .valine-card {
        margin: 1.5rem auto;
    }

    .valine-card .card-content {
        padding: 20px 20px 5px 20px;
    }

    #vcomments input[type=text],
    #vcomments input[type=email],
    #vcomments input[type=url],
    #vcomments textarea {
        box-sizing: border-box;
    }

    #vcomments p {
        margin: 2px 2px 10px;
        font-size: 1.05rem;
        line-height: 1.78rem;
    }

    #vcomments blockquote p {
        text-indent: 0.2rem;
    }

    #vcomments a {
        padding: 0 2px;
        color: #42b983;
        font-weight: 500;
        text-decoration: underline;
    }

    #vcomments img {
        max-width: 100%;
        height: auto;
        cursor: pointer;
    }

    #vcomments ol li {
        list-style-type: decimal;
    }

    #vcomments ol,
    ul {
        display: block;
        padding-left: 2em;
        word-spacing: 0.05rem;
    }

    #vcomments ul li,
    ol li {
        display: list-item;
        line-height: 1.8rem;
        font-size: 1rem;
    }

    #vcomments ul li {
        list-style-type: disc;
    }

    #vcomments ul ul li {
        list-style-type: circle;
    }

    #vcomments table, th, td {
        padding: 12px 13px;
        border: 1px solid #dfe2e5;
    }

    #vcomments table, th, td {
        border: 0;
    }

    table tr:nth-child(2n), thead {
        background-color: #fafafa;
    }

    #vcomments table th {
        background-color: #f2f2f2;
        min-width: 80px;
    }

    #vcomments table td {
        min-width: 80px;
    }

    #vcomments h1 {
        font-size: 1.85rem;
        font-weight: bold;
        line-height: 2.2rem;
    }

    #vcomments h2 {
        font-size: 1.65rem;
        font-weight: bold;
        line-height: 1.9rem;
    }

    #vcomments h3 {
        font-size: 1.45rem;
        font-weight: bold;
        line-height: 1.7rem;
    }

    #vcomments h4 {
        font-size: 1.25rem;
        font-weight: bold;
        line-height: 1.5rem;
    }

    #vcomments h5 {
        font-size: 1.1rem;
        font-weight: bold;
        line-height: 1.4rem;
    }

    #vcomments h6 {
        font-size: 1rem;
        line-height: 1.3rem;
    }

    #vcomments p {
        font-size: 1rem;
        line-height: 1.5rem;
    }

    #vcomments hr {
        margin: 12px 0;
        border: 0;
        border-top: 1px solid #ccc;
    }

    #vcomments blockquote {
        margin: 15px 0;
        border-left: 5px solid #42b983;
        padding: 1rem 0.8rem 0.3rem 0.8rem;
        color: #666;
        background-color: rgba(66, 185, 131, .1);
    }

    #vcomments pre {
        font-family: monospace, monospace;
        padding: 1.2em;
        margin: .5em 0;
        background: #272822;
        overflow: auto;
        border-radius: 0.3em;
        tab-size: 4;
    }

    #vcomments code {
        font-family: monospace, monospace;
        padding: 1px 3px;
        font-size: 0.92rem;
        color: #e96900;
        background-color: #f8f8f8;
        border-radius: 2px;
    }

    #vcomments pre code {
        font-family: monospace, monospace;
        padding: 0;
        color: #e8eaf6;
        background-color: #272822;
    }

    #vcomments pre[class*="language-"] {
        padding: 1.2em;
        margin: .5em 0;
    }

    #vcomments code[class*="language-"],
    pre[class*="language-"] {
        color: #e8eaf6;
    }

    #vcomments [type="checkbox"]:not(:checked), [type="checkbox"]:checked {
        position: inherit;
        margin-left: -1.3rem;
        margin-right: 0.4rem;
        margin-top: -1px;
        vertical-align: middle;
        left: unset;
        visibility: visible;
    }

    #vcomments b,
    strong {
        font-weight: bold;
    }

    #vcomments dfn {
        font-style: italic;
    }

    #vcomments small {
        font-size: 85%;
    }

    #vcomments cite {
        font-style: normal;
    }

    #vcomments mark {
        background-color: #fcf8e3;
        padding: .2em;
    }

    #vcomments table, th, td {
        padding: 12px 13px;
        border: 1px solid #dfe2e5;
    }

    table tr:nth-child(2n), thead {
        background-color: #fafafa;
    }

    #vcomments table th {
        background-color: #f2f2f2;
        min-width: 80px;
    }

    #vcomments table td {
        min-width: 80px;
    }

    #vcomments [type="checkbox"]:not(:checked), [type="checkbox"]:checked {
        position: inherit;
        margin-left: -1.3rem;
        margin-right: 0.4rem;
        margin-top: -1px;
        vertical-align: middle;
        left: unset;
        visibility: visible;
    }
</style>

<div class="card valine-card" data-aos="fade-up">
    <div id="vcomments" class="card-content"></div>
</div>

<script src="/libs/valine/av-min.js"></script>
<script src="/libs/valine/Valine.min.js"></script>
<script>
    new Valine({
        el: '#vcomments',
        appId: 'Vc276uuqkd8y8heuqzShe9p1-gzGzoHsz',
        appKey: 'bUwy6lANpgeVdpcQamMtC8QD',
        notify: 'false' === 'true',
        verify: 'false' === 'true',
        visitor: 'true' === 'true',
        avatar: 'mm',
        pageSize: '10',
        lang: 'zh-cn',
        placeholder: '快来快活呀！^_^'
    });
</script>
    

    

<article id="prenext-posts" class="prev-next articles">
    <div class="row article-row">
        
        <div class="article col s12 m6 overflow-policy" data-aos="fade-up">
            <div class="article-badge left-badge text-color">
                <i class="fa fa-chevron-left"></i>&nbsp;上一篇</div>
            <div class="card">
                <a href="/2019/04/07/zuo-pin-ji-yu-stm32-att7022-de-dan-xiang-yong-dian-qi-fen-xi-jian-ce-zhuang-zhi/">
                    <div class="card-image">
                        
                        
                        <img src="/medias/featureimages/9.jpg" class="responsive-img" alt="基于STM32+ATT7022的单相用电器分析监测装置">
                        
                        <span class="card-title">基于STM32+ATT7022的单相用电器分析监测装置</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            1、前言大学期间，电子类的比赛比较重要的比赛应该就是每年暑假的省/国家级大学生电子设计竞赛吧，其中省赛是偶数年，国赛是奇数年，小编都有参加过，上一篇分享了我们团队参加2016年省赛做的循迹小车，感兴趣的朋友可移步至基于STM32+LDC10
                        
                    </div>
                    <div class="publish-info">
                        <span class="publish-date">
                            <i class="fa fa-clock-o fa-fw icon-date"></i>2019-04-07
                        </span>
                        <span class="publish-author">
                            
                            <i class="fa fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/categories/嵌入式/" class="post-category" target="_blank">
                                    嵌入式
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/tags/嵌入式/" target="_blank">
                        <span class="chip bg-color">嵌入式</span>
                    </a>
                    
                    <a href="/tags/STM32/" target="_blank">
                        <span class="chip bg-color">STM32</span>
                    </a>
                    
                    <a href="/tags/作品/" target="_blank">
                        <span class="chip bg-color">作品</span>
                    </a>
                    
                    <a href="/tags/电能采集/" target="_blank">
                        <span class="chip bg-color">电能采集</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
        
        <div class="article col s12 m6 overflow-policy" data-aos="fade-up">
            <div class="article-badge right-badge text-color">
                下一篇&nbsp;<i class="fa fa-chevron-right"></i>
            </div>
            <div class="card">
                <a href="/2019/03/26/c-yu-yan-dai-can-hong-ding-yi-er/">
                    <div class="card-image">
                        
                        
                        <img src="/medias/featureimages/22.jpg" class="responsive-img" alt="【C语言】带参宏定义（二）">
                        
                        <span class="card-title">【C语言】带参宏定义（二）</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            1、什么是带参宏？带参宏在我们的嵌入式编程中使用得非常多，其定义如下：
define 标识符(参数列表) 字符序列
其中参数列表中的参数之间用逗号分隔，字符序列中应包含参数表中的参数。在定义带参数的宏时，宏名标识符与左圆括号之间不允许有空白
                        
                    </div>
                    <div class="publish-info">
                            <span class="publish-date">
                                <i class="fa fa-clock-o fa-fw icon-date"></i>2019-03-26
                            </span>
                        <span class="publish-author">
                            
                            <i class="fa fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/categories/C语言/" class="post-category" target="_blank">
                                    C语言
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/tags/宏定义/" target="_blank">
                        <span class="chip bg-color">宏定义</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
    </div>
</article>
</div>



    </div>
    <div id="toc-aside" class="expanded col l3 hide-on-med-and-down">
        <div class="toc-widget">
            <div class="toc-title"><i class="fa fa-list-alt"></i>&nbsp;&nbsp;目录</div>
            <div id="toc-content"></div>
        </div>
    </div>
</div>

<!-- TOC 悬浮按钮. -->

<div id="floating-toc-btn" class="hide-on-med-and-down">
    <a class="btn-floating btn-large bg-color">
        <i class="fa fa-list"></i>
    </a>
</div>


<script src="/libs/tocbot/tocbot.min.js"></script>
<script>
    $(function () {
        tocbot.init({
            tocSelector: '#toc-content',
            contentSelector: '#articleContent',
            headingsOffset: -($(window).height() * 0.4 - 45),
            // headingsOffset: -205,
            headingSelector: 'h2, h3, h4'
        });

        // modify the toc link href to support Chinese.
        let i = 0;
        let tocHeading = 'toc-heading-';
        $('#toc-content a').each(function () {
            $(this).attr('href', '#' + tocHeading + (++i));
        });

        // modify the heading title id to support Chinese.
        i = 0;
        $('#articleContent').children('h2, h3, h4').each(function () {
            $(this).attr('id', tocHeading + (++i));
        });

        // Set scroll toc fixed.
        let tocHeight = parseInt($(window).height() * 0.4 - 64);
        let $tocWidget = $('.toc-widget');
        $(window).scroll(function () {
            let scroll = $(window).scrollTop();
            /* add post toc fixed. */
            if (scroll > tocHeight) {
                $tocWidget.addClass('toc-fixed');
            } else {
                $tocWidget.removeClass('toc-fixed');
            }
        });

        
        /* 修复文章卡片 div 的宽度. */
        let fixPostCardWidth = function (srcId, targetId) {
            let srcDiv = $('#' + srcId);
            if (srcDiv.length === 0) {
                return;
            }

            let w = srcDiv.width();
            if (w >= 450) {
                w = w + 21;
            } else if (w >= 350 && w < 450) {
                w = w + 18;
            } else if (w >= 300 && w < 350) {
                w = w + 16;
            } else {
                w = w + 14;
            }
            $('#' + targetId).width(w);
        };

        // 切换TOC目录展开收缩的相关操作.
        const expandedClass = 'expanded';
        let $tocAside = $('#toc-aside');
        let $mainContent = $('#main-content');
        $('#floating-toc-btn .btn-floating').click(function () {
            if ($tocAside.hasClass(expandedClass)) {
                $tocAside.removeClass(expandedClass).slideUp(500);
                $mainContent.removeClass('l9');
            } else {
                $tocAside.addClass(expandedClass).slideDown(500);
                $mainContent.addClass('l9');
            }
            fixPostCardWidth('artDetail', 'prenext-posts');
        });
        
    });
</script>
    

</main>


<footer class="page-footer bg-color">
    <div class="container row center-align">
        <div class="col s12 m8 l8 copy-right">
            本站由&copy;<a href="https://zhengnianli.github.io/" target="_blank">ZhengNian</a>基于
            <a href="https://hexo.io/" target="_blank">Hexo</a> 的
            <a href="https://github.com/blinkfox/hexo-theme-matery" target="_blank">hexo-theme-matery</a>主题搭建.

            
                &nbsp;<i class="fa fa-area-chart"></i>&nbsp;站点总字数:&nbsp;
                <span class="white-color">187.2k</span>
            

            
			
                <br>
                
                <span id="busuanzi_container_site_pv">
                    <i class="fa fa-heart-o"></i>
                    本站总访问量 <span id="busuanzi_value_site_pv" class="white-color"></span>
                </span>
                
                
                <span id="busuanzi_container_site_uv">
                    <i class="fa fa-users"></i>
                    次,&nbsp;访客数 <span id="busuanzi_value_site_uv" class="white-color"></span> 人.
                </span>
                
            
        </div>
        <div class="col s12 m4 l4 social-link social-statis">
    <a href="https://github.com/zhengnianli" class="tooltipped" target="_blank" data-tooltip="访问我的GitHub" data-position="top" data-delay="50">
        <i class="fa fa-github"></i>
    </a>



    <a href="mailto:2238184039@qq.com" class="tooltipped" target="_blank" data-tooltip="邮件联系我" data-position="top" data-delay="50">
        <i class="fa fa-envelope-open"></i>
    </a>



    <a href="tencent://AddContact/?fromId=50&fromSubId=1&subcmd=all&uin=2238184039" class="tooltipped" data-tooltip="QQ联系我: 2238184039" data-position="top" data-delay="50">
        <i class="fa fa-qq"></i>
    </a>



    <a href="/atom.xml" class="tooltipped" target="_blank" data-tooltip="RSS 订阅" data-position="top" data-delay="50">
        <i class="fa fa-rss"></i>
    </a>
</div>
    </div>
</footer>

<div class="progress-bar"></div>


<!-- 搜索遮罩框 -->
<div id="searchModal" class="modal">
    <div class="modal-content">
        <div class="search-header">
            <span class="title"><i class="fa fa-search"></i>&nbsp;&nbsp;搜索</span>
            <input type="search" id="searchInput" name="s" placeholder="请输入搜索的关键字" class="search-input">
        </div>
        <div id="searchResult"></div>
    </div>
</div>

<script src="/js/search.js"></script>
<script type="text/javascript">
$(function () {
    searchFunc("/" + "search.xml", 'searchInput', 'searchResult');
});
</script>
<!-- 回到顶部按钮 -->
<div id="backTop" class="top-scroll">
    <a class="btn-floating btn-large waves-effect waves-light" href="#!">
        <i class="fa fa-angle-up"></i>
    </a>
</div>


<script src="/libs/materialize/materialize.min.js"></script>
<script src="/libs/masonry/masonry.pkgd.min.js"></script>
<script src="/libs/aos/aos.js"></script>
<script src="/libs/scrollprogress/scrollProgress.min.js"></script>
<script src="/libs/lightGallery/js/lightgallery-all.min.js"></script>
<script src="/js/matery.js"></script>

<!-- Global site tag (gtag.js) - Google Analytics -->



    <script src="/libs/others/clicklove.js"></script>


    <script async src="/libs/others/busuanzi.pure.mini.js"></script>


</body>
</html>